<template>
    <view class="columnbox wdh-100 content">
        <view class="columnbox one-info">
            <view class="rowbox wdh-100 spb" style="align-items: flex-end;">
                <view class="rowbox">
                    <image :src="info.avatar" mode="aspectFill" class="user-img"></image>
                    <view class="columnbox als">
                        <view class="userName">{{info.userName}}</view>
                        <view class="desc">{{info.createTime}} 加入</view>
                    </view>
                </view>
                <view class="rowbox btn-box">
                    <image @click="deletInfo" src="/static/img/delet.png" mode="widthFix"></image>
                    <image @click="updateInfo" src="/static/img/edit.svg" mode="widthFix"></image>
                </view>
            </view>
        </view>
    </view>
</template>

<script>
    export default {
        data() {
            return {
                id: '',
                info: '',
                refreshflag: false
            };
        },
        onShow() {
            if (this.refreshflag) {
                this.refreshflag = false
                this.getDetail()
            }
        },
        onLoad(options) {
            this.id = options.id
            this.getDetail()
        },
        methods: {
            updateInfo() {
                uni.navigateTo({
                    url: '/packageA/staff/add?id=' + this.id
                })
            },
            getDetail() {
                this.$req.get(`/xcx/stationWorker/${this.id}`).then(res => {
                    this.info = res.data.data
                })
            },
            deletInfo() {
                uni.showModal({
                    title: '是否确认删除',
                    success: (res) => {
                        if (res.confirm) {
                            uni.showLoading({
                                title: '正在删除'
                            })
                            this.$req.del(`/xcx/stationWorker/${this.id}`).then(res => {
                                uni.hideLoading()
                                if (res.data.code == 200) {
                                    uni.showModal({
                                        title: '删除成功',
                                        content: '',
                                        success: () => {
                                            let pages = getCurrentPages(); //获取所有页面栈实例列表
                                            let nowPage = pages[pages.length -
                                                1]; //当前页页面实例
                                            let prevPage = pages[pages.length -
                                                2]; //上一页页面实例
                                            prevPage.$vm.refreshflag = true
                                            uni.navigateBack()
                                        }
                                    })
                                } else {
                                    uni.showModal({
                                        title: res.data.msg,
                                        success: () => {}
                                    })
                                }
                            })
                        }
                    }
                })
            },
        }
    }
</script>


<style lang="scss" scoped>
    .content {
        background: #f7f8fa;
        min-height: 100vh;
        justify-content: flex-start;
        font-family: PingFang SC;
        width: 100%;
        overflow: hidden;
    }

    .one-info {
        margin: 10rpx 0;
        width: 710rpx;
        border-radius: 20rpx;
        background: #fff;
        padding: 32rpx 32rpx;
    }

    .user-img {
        width: 100rpx;
        height: 100rpx;
        border-radius: 100rpx;
        margin-right: 20rpx;
    }

    .userName {
        font-size: 32rpx;
        line-height: 40rpx;
    }

    .desc {
        font-size: 28rpx;
        margin-top: 20rpx;
        color: #7c7e90;
        line-height: 40rpx;
    }

    .phonenumber {
        font-size: 28rpx;
        margin-top: 20rpx;
        line-height: 40rpx;
    }

    .b-box {
        border-top: #eff1f7 solid 1px;
        font-size: 28rpx;
        margin-top: 20rpx;
        padding-top: 20rpx;
        color: #7c7e90;
    }

    .btn-box {
        image {
            width: 32rpx;
            height: 32rpx;
            margin-left: 40rpx;
        }
    }
</style>